package cn.zch.soft.util.hutool.http;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
public class TestWebServices {
  public static void main(String[] args) throws Exception {
    //GetUserInfoByGuyidAName()
    // insertChargeRecordAction()
    getWeatherbyCityName();
  }
  public static void GetUserInfoByGuyidAName() throws RemoteException, ServiceException, MalformedURLException {
    // http://s.tunnel.qydev.com/webService/UserInfoService.asmx?op=GetUserInfoList
    // http://s.tunnel.qydev.com/webService/UserInfoService.asmx?op=GetUserInfoByGuyidAName
    // 请求参数：guyid 学号 varchar(18) ，name 姓名varchar(20)
    String guyid = "20150105";
    String name = "陈夏";
    Service service = new Service();
    // URL地址
    String url = "http://s.tunnel.qydev.com/webService/UserInfoService.asmx";
    String namespace = "http://www.singbon.com/";
    // Action路径
    String actionUri = "GetUserInfoByGuyidAName";
    // 要调用的方法名
    String op = "GetUserInfoByGuyidAName";
    Call call = (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(url));
    call.setUseSOAPAction(true);
    // action uri
    // call.setSOAPActionURI("http://www.singbon.com/GetUserInfoByGuyidAName");
    call.setSOAPActionURI(namespace + actionUri);
    // 设置要调用哪个方法
    call.setOperationName(new QName(namespace, op));
    // 设置参数名称，具体参照从浏览器中看到的
    // 设置请求参数及类型
    call.addParameter(new QName(namespace, "guyid"), XMLType.XSD_STRING, ParameterMode.IN);
    // 设置请求参数及类型
    call.addParameter(new QName(namespace, "name"), XMLType.XSD_STRING, ParameterMode.IN);
    //设置返回结果为是某个类
    // call.setReturnType(new QName(namespace,"getinfo"),Model.class);
    // 设置结果返回类型
    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
    Object[] params = new Object[]{guyid, name};
    // 方法执行后的返回值
    String result = (String) call.invoke(params);
    System.out.println(call.invoke(params));
    System.out.println(result);
  }
  public static void insertChargeRecord() throws RemoteException, ServiceException, MalformedURLException {
    // http://s.tunnel.qydev.com/webService/UserInfoService.asmx?op=GetUserInfoList
    // http://s.tunnel.qydev.com/webService/UserInfoService.asmx?op=GetUserInfoByGuyidAName
    // 请求参数：guyid 学号 varchar(18) ，name 姓名varchar(20)
    //1	5.0	20150105	20150104.0	陈夏	158248210718	1	0	201801260001	201801260001	201801260001	100	2018-01-26 16:44:59
    String userid = "5.0";
    String guyid = "20150105";
    String cardnum = "20150104";
    String name = "陈夏";
    String phone = "158248210718";
    String version = "4";
    String status = "0";
    String orderId = "201801260001";
    String orderSeq = "201801260001";
    String tranSeq = "";
    String amount = "100";
    String orderDate = "2018-01-26 16:44:59";
    String chargeDate = "";
    Service service = new Service();
    // URL地址
    String url = "http://s.tunnel.qydev.com/webService/RemoteCharge.asmx";
    String namespace = "http://www.singbon.com/";
    // Action路径
    String actionUri = "insertChargeRecord";
    // 要调用的方法名
    String op = "insertChargeRecord";
    Call call = (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(url));
    call.setUseSOAPAction(true);
    // action uri
    call.setSOAPActionURI("http://www.singbon.com/insertChargeRecord");
    call.setOperationName(new QName(namespace, op));// 设置要调用哪个方法
    //  设置请求参数及类型 设置参数名称，具体参照从浏览器中看到的
    call.addParameter(new QName(namespace, "userid"), XMLType.XSD_FLOAT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "guyid"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "cardnum"), XMLType.XSD_FLOAT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "name"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "phone"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "version"), XMLType.XSD_INT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "status"), XMLType.XSD_INT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "orderId"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "orderSeq"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "tranSeq"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "amount"), XMLType.XSD_INT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "orderDate"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "chargeDate"), XMLType.XSD_STRING, ParameterMode.IN);
    // call.setReturnType(new QName(namespace,"getinfo"),Model.class); //设置返回结果为是某个类
    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置结果返回类型
    Object[] params = new Object[]{userid, guyid, cardnum, name, phone, version, status, orderId, orderSeq, tranSeq, amount, orderDate, chargeDate};
    String result = (String) call.invoke(params); // 方法执行后的返回值
    System.out.println(result);
  }
  public static void insertChargeRecordAction() throws RemoteException, ServiceException, MalformedURLException {
    // http://s.tunnel.qydev.com/webService/UserInfoService.asmx?op=GetUserInfoList
    // http://s.tunnel.qydev.com/webService/UserInfoService.asmx?op=GetUserInfoByGuyidAName
    // 请求参数：guyid 学号 varchar(18) ，name 姓名varchar(20)
    //1	5.0	20150105	20150104.0	陈夏	158248210718	1	0	201801260001	201801260001	201801260001	100	2018-01-26 16:44:59
    String userid = "5.0";
    String guyid = "20150105";
    String cardnum = "20150104";
    String name = "陈夏";
    String phone = "158248210718";
    String version = "4";
    String status = "0";
    String orderId = "201801260001";
    String orderSeq = "201801260001";
    String tranSeq = "";
    String amount = "100";
    String orderDate = "2018-01-26 16:44:59";
    String chargeDate = "";
    Service service = new Service();
    //String url = "http://s.tunnel.qydev.com/T1803/RemoteCharge.asmx"; // URL地址
    String url = "http://s.tunnel.qydev.com/T180320/RemoteCharge.asmx"; // URL地址
    String namespace = "http://www.singbon.com/";
    String actionUri = "insertChargeRecord"; // Action路径
    String op = "insertChargeRecord"; // 要调用的方法名
    Call call = (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(url));
    call.setUseSOAPAction(true);
    call.setSOAPActionURI("http://www.singbon.com/insertChargeRecord"); // action uri
    call.setOperationName(new QName(namespace, op));// 设置要调用哪个方法
    // 设置请求参数及类型 设置参数名称，具体参照从浏览器中看到的
    call.addParameter(new QName(namespace, "userid"), XMLType.XSD_FLOAT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "guyid"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "cardnum"), XMLType.XSD_FLOAT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "name"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "phone"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "version"), XMLType.XSD_INT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "status"), XMLType.XSD_INT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "orderId"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "orderSeq"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "tranSeq"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "amount"), XMLType.XSD_INT, ParameterMode.IN);
    call.addParameter(new QName(namespace, "orderDate"), XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter(new QName(namespace, "chargeDate"), XMLType.XSD_STRING, ParameterMode.IN);
    //设置返回结果为是某个类
    // call.setReturnType(new QName(namespace,"getinfo"),Model.class);
    // 设置结果返回类型
    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
    Object[] params = new Object[]{userid, guyid, cardnum, name, phone, version, status, orderId, orderSeq, tranSeq, amount, orderDate, chargeDate};
    // 方法执行后的返回值
    String result = (String) call.invoke(params);
    System.out.println(result);
  }
  /**
   * 测试 java 调用 C# webservices 接口 天气预报
   */
  public static void getWeatherbyCityName() throws RemoteException, ServiceException, MalformedURLException {
    String cityName = "郑州";
    Service service = new Service();
    // http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName
    String url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
    String namespace = "http://WebXml.com.cn/";
    // Action路径
    String actionUri = "WeatherWebServiceSoap";
    // 要调用的方法名
    String op = "getWeatherbyCityName";
    Call call = (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(url));
    call.setUseSOAPAction(true);
    // action uri
    call.setSOAPActionURI(namespace + actionUri);
    // 设置要调用哪个方法
    call.setOperationName(new QName(namespace, op));
    // 设置请求参数及类型 设置参数名称，具体参照从浏览器中看到的
    call.addParameter(new QName(namespace, "theCityName"), XMLType.XSD_FLOAT, ParameterMode.IN);
    //设置返回结果为是某个类
    // call.setReturnType(new QName(namespace,"getinfo"),Model.class);
    // 设置结果返回类型
    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
    Object[] params = new Object[]{cityName};
    // 方法执行后的返回值
    String result = (String) call.invoke(params);
    System.out.println(result);
  }
}